%{
  #include <stdio.h>
  #include "../Operation.h"
  double result[1];
  double v_phi[1];
  double v_theta[1];
%}

%token MORE LESS DIVISION MULTIPLICATION RESULT EQUAL COS SIN LN LOG PI LEFT_P RIGHT_P PHI THETA
%union {
  char *string;
  double number;
  void* none;
}
%token<number> NUM
%type<none> Expression Line
%left MORE LESS
%left DIVISION MULTIPLICATION
%start Input
%%
Input:/* Empty */
	| Line RESULT
	;			

Line : RESULT				{}
	| Expression RESULT		{ result[0]=$<number>1; }
	;

Expression : Expression MORE Expression		{ $<number>$=plus($<number>1,$<number>3); }
	| Expression LESS Expression		{ $<number>$=moins($<number>1,$<number>3); }
	| Expression DIVISION Expression	{ $<number>$=divide($<number>1,$<number>3); }
	| Expression MULTIPLICATION Expression	{ $<number>$=multiply($<number>1,$<number>3); }
	| COS LEFT_P Expression RIGHT_P		{ $<number>$=cosinus($<number>3); }
	| SIN LEFT_P Expression RIGHT_P		{ $<number>$=sinus($<number>3); }
	| LN LEFT_P Expression RIGHT_P		{ $<number>$=ln($<number>3); }
	| NUM					{ $<number>$=$<number>1; }
	| PHI					{ $<number>$=v_phi[0]; }
	| THETA					{ $<number>$=v_theta[0]; }
	;

%%
FILE* yyin;
void readFile(double retour[], double* _phi, double* _theta) {
  v_phi[0] = *(_phi);
  v_theta[0] = *(_theta);
  yyparse();
  retour[0] = result[0];
}

void yyerror() {
}

int yywrap() {
 return 1;
}
